class Solution {
    boolean ans = true;
    public boolean isBalanced(TreeNode root) {
        seek(root);
        return ans;
    }
    public int seek(TreeNode root){
        if(root == null)
            return 0;
        int h1 = seek(root.left);
        int h2 = seek(root.right);
        if( Math.abs(h1-h2)>1 )
            ans = false;
        // System.out.println(h1+" "+h2);
        return Math.max(h1,h2)+1;
    }
}